<template>
	<el-dialog title="测试结果上传" :visible.sync="visible" width="800px" :center="false" >
		 <div slot="title" class="dialog-header-title">
			<i class="el-icon-upload2" style="color: #FFF"></i>&nbsp;
			<span style="color: #FFF">测试结果上传</span>
		</div> 

		 <div  >
			<el-form :inline="false" label-width="100px" size="mini" ref="form" :model="form" :rules="rules">
				<el-row>
					<el-col :span="12">
						<el-form-item label="交易码:" prop="transCode">
							<el-input v-model="form.transCode" disabled></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="交易名称:" prop="transName">
							<el-input v-model="form.transName" disabled></el-input>
						</el-form-item>
					</el-col>
					
					<el-col :span="12">
						<el-form-item label="服务编码(R):" prop="busCode">
							<el-input v-model="form.busCode" disabled></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="服务编码(P):" prop="pubCode">
							<el-input v-model="form.pubCode" disabled></el-input>
						</el-form-item>
					</el-col>
					
					<el-col :span="12">
						<el-form-item label="服务系统:" prop="regSysCode">
							<el-input v-model="form.regSysCode" disabled></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="消费系统:" prop="systemNo">
							<el-input v-model="form.systemNo" disabled></el-input>
						</el-form-item>
					</el-col>
					
					
					
					<el-col :span="24">
						<el-form-item label="测试结果:" prop="testResult">
							<el-select v-model="form.testResult" style="width: 100%" placeholder="测试结果">
								<el-option v-for="item in dict('SMP0033')" :key="item.itemCode"
									:label="item.itemName" :value="item.itemCode">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="文件:" prop="aa"  style="text-align: left;">
						<el-upload  :on-change="changeFile" :multiple="false" :limit="1" :auto-upload="false" :file-list="fileList" action="#">
							<el-button size="mini"  style="width: 100%;" type="primary"><i class="el-icon-upload"/>添加图片</el-button>
						</el-upload>
						</el-form-item>
					</el-col>
					
					
				</el-row>
			</el-form> 
		 </div> 
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false" size="mini">取 消</el-button>
			<el-button type="primary" @click="submit" size="mini" plain>确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
	"use strict";
		import { initFile, initOESBFile } from '@/api/release.js';
		import { getEsbEnvironmentByEsbFlg } from '@/api/environment.js';
		import { addTestResult } from '@/api/service.js';
		
	export default {
		data() {
			return {
				visible:false,
				fileList:[],
				fileOldName:'',
				
				form:{
					transCode:'',
					transName:'',
					busCode:'',
					pubCode:'',
					regSysCode:'',
					systemNo:'',
					testResult:'',
					fileName: "",
					fileDescribe: "",
				},
				rules: {
					testResult: [{
						required: true,
						message: '请输入测试结果',
						trigger: 'blur'
					}]
				}
			}
			
		},
		
		created() {
			this.getEsbEnvironmentList();
		},
		
		methods: {
			
			
			changeFile(file,fileList){
				console.info(fileList);
				this.fileList = fileList;
			},
			
			
			getEsbEnvironmentList(){
				getEsbEnvironmentByEsbFlg({"esbFlg":"01"}).then(response=>{
					this.esbEnvironmentList = response.data.extend; 
				})
			},
			ShowDialog(row){
				this.visible = true;
				Object.assign(this.form,row);
			},
			submit(){
				this.$refs["form"].validate((valid)=>{
				if(valid){
					
					//上传图片附件
					var data = new FormData();
					data.append("file",this.fileList[0].raw);
					data.append("fileName",this.form.fileName);
					data.append("fileDescribe",this.form.fileDescribe);
					
					data.append("testResult",this.form.testResult);
					data.append("pubCode",this.form.pubCode);
					data.append("regSysCode",this.form.regSysCode);
					data.append("pubSysCode",this.form.systemNo);
					addTestResult(data).then(response => {
						if(response.data.code == "0000"){
							this.$message.success(response.data.message);
						}else{
							this.$message.error(response.data.message);
						}
					}).catch(error => {
						this.$message.error(error.message);
					});
					
					this.visible = false;
				}
				});
			}
		},
		
		
	};
</script>
